﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;
using System.Data.Common;
namespace MINERP.DAL.Statistics
{
    public class ShopBalanceMoveDAL
    {

        public static DataSet GetAccoundRecord(int shopid, DateTime startTime, DateTime endTime)
        {
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand("GetShopAccountRecord");
            db.AddInParameter(dbCommand, "@shopId", DbType.Int32, shopid);
            db.AddInParameter(dbCommand, "@startTime", DbType.DateTime, startTime);
            db.AddInParameter(dbCommand, "@endTime", DbType.DateTime, endTime);
            return db.ExecuteDataSet(dbCommand);
        }

        public static DataSet GetSalesmanAccountRecord(string salesmanName, DateTime startTime, DateTime endTime,int operationType)
        {
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand("GetSalesmanAccountRecord");
            db.AddInParameter(dbCommand, "@salesmanName", DbType.String, salesmanName);
            db.AddInParameter(dbCommand, "@startTime", DbType.DateTime, startTime);
            db.AddInParameter(dbCommand, "@endTime", DbType.DateTime, endTime);
            db.AddInParameter(dbCommand, "@operationType", DbType.Int32, operationType);
            return db.ExecuteDataSet(dbCommand);
        }

        public static DataSet GetAccoundRecord(int shopid, DateTime startTime, DateTime endTime,string inStrtype)
        {
            Database db = DatabaseFactory.CreateDatabase();
           
            List<DataSet> listset = new List<DataSet>();
            foreach (string typeStr in inStrtype.Split(','))
            {
                DbCommand dbCommand = db.GetStoredProcCommand("GetShopAccountRecord2");
                db.AddInParameter(dbCommand, "@shopId", DbType.Int32, shopid);
                db.AddInParameter(dbCommand, "@startTime", DbType.DateTime, startTime);
                db.AddInParameter(dbCommand, "@endTime", DbType.DateTime, endTime);
                db.AddInParameter(dbCommand, "@typeid", DbType.Int16, Convert.ToInt16(typeStr));
                listset.Add(db.ExecuteDataSet(dbCommand));

            }
            for (int i = 1; i < listset.Count; i++)
            {
                listset[0].Merge(listset[i], true, MissingSchemaAction.AddWithKey);
            }
            return listset[0];
        }
    }
}
